home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / freeli20.zip / progs / bin2hex.asm < prev    next >
Assembly Source File  |  1996-07-01  |  3KB  |  95 lines

  1. Ideal
  2.  
  3. Public      main
  4. Extrn       startup:near
  5.  
  6. Macro       lcall p,a,b,c,d,e,f,g,h ;; library call
  7.  
  8.             ifnb <a>
  9.               push a                ;; if args, push first arg
  10.               lcall p,b,c,d,e,f,g,h ;; and recurse . . .
  11.             else
  12.               extrn p:near          ;; declare procedure
  13.               call p                ;; call procedure
  14.             endif
  15.  
  16. EndM
  17.  
  18. Model Tiny
  19. CodeSeg
  20. P186
  21. Org 100h
  22.  
  23. Start:      jmp startup
  24.  
  25. ;****************** Strings Section
  26.  
  27. Syntax      db 'Syntax:  BIN2HEX <infile> <outfile>',0
  28.  
  29. ;****************** 'main' procedure
  30.  
  31. Proc        main
  32.  
  33.             lcall fsetbuf 16384     ;Set file buffers to 16K
  34.  
  35.             cmp cx,2                ;Wrong number of args?
  36.             jne m_syntax
  37.  
  38.             lcall fopen [di],0      ;Open input file
  39.             test ax,ax              ;File not found?
  40.             jz m_syntax
  41.             xchg bp,ax              ;BP = handle
  42.  
  43.             lcall fopen [di+2],3    ;Open output file
  44.             test ax,ax              ;Check for errors
  45.             jnz m_ok1
  46.             lcall fclose bp         ;Close input file
  47.             jmp m_syntax            ;Go print syntax
  48.  
  49. m_ok1:      xchg di,ax              ;DI = handle
  50.             xor dx,dx               ;DX = char counter
  51.  
  52. m_loop:     lcall fgetc bp          ;Get char
  53.             test ax,ax              ;EOF, done
  54.             jl m_finish
  55.  
  56.             push ax                 ;Save AX
  57.             shr al,4                ;Get first hex digit
  58.             cmp al,0Ah
  59.             sbb al,69h
  60.             das
  61.             lcall fputc di,ax       ;Output char
  62.  
  63.             pop ax
  64.             and al,0Fh              ;Get second hex digit
  65.             cmp al,0Ah
  66.             sbb al,69h
  67.             das
  68.             lcall fputc di,ax       ;Output char
  69.  
  70.             inc dx                  ;Increment char counter
  71.             cmp dx,35               ;End of line?
  72.             jb m_loop
  73.  
  74.             lcall fputc di,13       ;Output CR, LF
  75.             lcall fputc di,10
  76.             xor dx,dx               ;Reset counter
  77.             jmp m_loop              ;Loop back
  78.  
  79. m_finish:   test dx,dx              ;Nothing on line?
  80.             jz m_done
  81.             lcall fputc di,13       ;Output CR, LF
  82.             lcall fputc di,10
  83.  
  84. m_done:     lcall fclose bp         ;Close files
  85.             lcall fclose di
  86.             ret                     ;Return
  87.  
  88. m_syntax:   push offset(Syntax)     ;Display 'Syntax' message
  89.             lcall puts
  90.             ret                     ;Return
  91.  
  92. EndP        main
  93.  
  94. End Start
  95.